# Maintainer: Ionut Biru <ibiru@archlinux.org>

pkgname=js38
pkgver=38.8.0
pkgrel=5
pkgdesc="JavaScript interpreter and libraries - Version 38"
arch=(x86_64)
url="https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Releases/38"
license=(MPL)
depends=(nspr gcc-libs readline zlib icu libffi)
makedepends=(python2 libffi zip)
options=(!staticlibs)
source=(https://ftp.mozilla.org/pub/firefox/releases/${pkgver}esr/source/firefox-${pkgver}esr.source.tar.bz2
        mozjs38-fix-tracelogger.patch
        mozjs38-shell-version.patch
        mozjs38-pkg-config-version.patch
        mozjs38-install-name.patch
        mozjs38-copy-headers.patch
        mozjs38-add-bracket.patch
        mozjs38-1269317.patch)
sha256sums=('9475adcee29d590383c4885bc5f958093791d1db4302d694a5d2766698f59982'
            '55e656c41583cd4e5468cb4b93c0f57f40f2817adcc1acf9333b4b248969983d'
            '16b00caf68c23d7b484b42b523ca49465853fee5161b34520cb93fc89bf16903'
            'fcdc86524d3abb89244310bded9e994833b1ecad2cb181821cbb523e2c1b567a'
            '56d1336f0bfa9b1d1a19313f3cdece317bf6a169c7369ecdc068e7ab99d16d9e'
            'd052a19e7d33023e927c83fda5dcf7a90127934df034969011960b3b8e6930ed'
            '3d3a53949da5d1da201548d9de41c99c1ff6d52e1ac7bc047e2c96e6c5f9e3a7'
            'e34338b3bfb1a16c3f98b73007b914560085d54ba94d56cb1b8586330cbef506')

prepare() {
  cd mozilla-esr38

  patch -Np1 -i ../mozjs38-fix-tracelogger.patch
  patch -Np1 -i ../mozjs38-shell-version.patch
  patch -Np1 -i ../mozjs38-pkg-config-version.patch
  patch -Np1 -i ../mozjs38-install-name.patch
  patch -Np1 -i ../mozjs38-copy-headers.patch
  patch -Np1 -i ../mozjs38-add-bracket.patch
  patch -Np1 -i ../mozjs38-1269317.patch
}

build() {
  unset CPPFLAGS
  CXXFLAGS+=' -fno-delete-null-pointer-checks -fpermissive -fno-tree-vrp -fno-strict-aliasing'
  CFLAGS+=' -fno-delete-null-pointer-checks -fpermissive -fno-tree-vrp -fno-strict-aliasing'
  export PYTHON=/usr/bin/python2
  cd mozilla-esr38/js/src
  ./configure --prefix=/usr --with-system-nspr --enable-system-ffi \
    --with-system-zlib --with-system-icu --with-intl-api --enable-ctypes \
    --enable-threadsafe --enable-system-ffi --enable-shared-js --enable-gcgenerational --disable-optimize --enable-pie
  make
}

check() {
  cd mozilla-esr38/js/src
  # Disabled: test suite fails because it is broken.
  #make -j1 check
}

package() {
  cd mozilla-esr38/js/src
  make DESTDIR="$pkgdir" install
  rm "$pkgdir"/usr/lib/*.ajs
  find "$pkgdir"/usr/{lib/pkgconfig,include} -type f -exec chmod -x {} +
}

# vim:set ts=2 sw=2 et:
